import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    { path: '/', redirect: '/manager/home', },
    // { path: '/home', name: 'home', component: () => import('../views/Home.vue'), },
    {
      path: '/manager', component: () => import('../views/Manager.vue'), children: [
        { path: 'test', name: 'test', meta: { title: '测试' }, component: () => import('../views/Test.vue') },
        { path: 'home', name: 'home', meta: { title: '首页' }, component: () => import('../views/Home.vue') },
        { path: 'data', name: 'data', meta: { title: '数据' }, component: () => import('../views/page/Data.vue') },
        { path: 'book', name: 'book', meta: { title: '书籍管理' }, component: () => import('../views/page/Book.vue') },
        { path: 'user', name: 'user', meta: { title: '账户管理' }, component: () => import('../views/page/User.vue') },
      ]
    },
    { path: '/404', name: '404', meta: { title: '404' }, component: () => import('../views/404.vue'), },
    { path: '/:pathMatch(.*)', redirect: '/404' },
  ],
})

router.beforeEach((to, from, next) => {
  document.title = to.meta.title
  next()
})

export default router
